package kuaidi.view.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import kuaidi.helper.R;
import kuaidi.view.adapter.ChoseCompanyAdapter;

public class CompanyActivity extends AppCompatActivity {

    @BindView(R.id.company_back_iv)
    ImageView companyBackIv;
    @BindView(R.id.company_xrcv)
    RecyclerView companyXrcv;
    private List<String> data;
    private ChoseCompanyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company);
        ButterKnife.bind(this);
        initData();
        createData();
    }

    private void createData() {

        data.add("申通快递");
        data.add("圆通快递");
        data.add("韵达快递");
        data.add("天天快递");
        data.add("EMS快递");
        data.add("中通快递");
        data.add("汇通快递");
        adapter.notifyDataSetChanged();
        adapter.setOnItemClickListener(new ChoseCompanyAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, String data) {
                Intent intent = new Intent();
                intent.putExtra("data", data);
                setResult(2, intent);

                //  结束当前页面(关闭当前界面)
                finish();
            }
        });
    }

    private void initData() {
        data = new ArrayList<>();
        adapter = new ChoseCompanyAdapter(data, getApplicationContext());
        companyXrcv.setLayoutManager(new GridLayoutManager(this, 1));
        companyXrcv.setAdapter(adapter);
    }
}
